﻿using GrapeCity.Forguncy.CellTypes;
using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Windows;
using Vant.Properties;
using Vant.WpfControls;
using Vant.WpfControls.DrawingObject;

namespace Vant.CellTypes
{
    public class SwipeDesigner : CellTypeDesigner<Swipe>, ISupportPropertyInitialize
    {
        public override FrameworkElement GetDrawingControl(ICellInfo cellInfo, IDrawingHelper drawingHelper)
        {
            return new SwipeDrawingObject(this.CellType, drawingHelper);
        }
        public void InitDefaultPropertyValues(IBuilderContext context)
        {
            CellType.indicatorColor = "Accent 1";
        }
    }

    [Designer("Vant.CellTypes.SwipeDesigner, Vant")]
    [Icon("pack://application:,,,/Vant;component/Resources/Images/Swipe.png")]
    [OrderWeight((int)Utils.OrderWeight.Swipe)] 
    public class Swipe : VantCellTypeBase
    {
        [SRDisplayName(nameof(Resources.Swipe_IsPreview))]
        [BoolProperty]
        [DefaultValue(true)]
        public bool preview { get; set; } = true;

        [SRDisplayName(nameof(Resources.Edit_ClickCommand))]
        [SRCustomCommandObject(IndentLevel = 1, InitParamProperties = "value", InitParamValues = nameof(Resources.Swipe_ClickCommand_InitParamValues))]
        public object ClickCommand { get; set; }

        [SRDisplayName(nameof(Resources.UseBinding))]
        [BoolProperty]
        [MergableProperty(false)]
        public bool useBinding { get; set; } = false;

        [SRDisplayName(nameof(Resources.Swipe_ConfigImageItems))]
        [ListProperty(IndentLevel = 1)]
        public List<ImageItem> imageItems { get; set; } = new List<ImageItem>();

        [SRBindingDataSourceProperty(Columns = nameof(Resources.Swipe_BindingDataSourceProperty_Columns), IndentLevel = 1)]
        [SRDisplayName(nameof(Resources.BindingOptions))]
        public object bindingOptions { get; set; }

        [SRDisplayName(nameof(Resources.Swipe_ScrollMode))]
        [SRRadioGroupProperty(ValueList = "false|true", DisplayList = nameof(Resources.Swipe_ScrollMode_Display))]
        [DefaultValue(false)]
        public bool vertical { get; set; } = false;

        [SRDisplayName(nameof(Resources.Swipe_Internal))]
        [SRIntProperty(Min = 0, AllowNull = true, Watermark = nameof(Resources.Swipe_NotAutoplay))]
        [DefaultValue(null)]
        public int? autoplay { get; set; }

        [SRDisplayName(nameof(Resources.Swipe_ShowIndicator))]
        [BoolProperty]
        [DefaultValue(true)]
        public bool showIndicators { get; set; } = true;

        [SRDisplayName(nameof(Resources.Swipe_IndicatorColor))]
        [ColorProperty]
        public string indicatorColor { get; set; }

        [SRCategoryHeader(nameof(Resources.Other))]
        [SRDisplayName(nameof(Resources.Swipe_Loop))]
        [DefaultValue(true)]
        public bool loop { get; set; } = true;

        [SRDisplayName(nameof(Resources.Swipe_ByGesture))]
        [DefaultValue(true)]
        public bool touchable { get; set; } = true;

        [RunTimeMethod]
        [SRDisplayName(nameof(Resources.Swipe_SwitchToPrev))]
        public void SwitchToPrev()
        {
            //
        }

        [RunTimeMethod]
        [SRDisplayName(nameof(Resources.Swipe_SwitchToNext))]
        public void SwitchToNext()
        {
            //
        }

        [RunTimeMethod]
        [SRDisplayName(nameof(Resources.Swipe_SwitchToSpecific))]
        public void SwitchTo(
            [SRItemDisplayName(nameof(Resources.Swipe_SwipeItemNumber))]
            [Required]
            int number
        )
        {
            //
        }

        public override bool GetDesignerPropertyVisible(string propertyName)
        {
            if (propertyName == nameof(ClickCommand))
            {
                return !preview;
            }
            if (propertyName == nameof(bindingOptions))
            {
                return useBinding;
            }
            if (propertyName == nameof(imageItems))
            {
                return !useBinding;
            }
            if (propertyName == nameof(indicatorColor))
            {
                return showIndicators;
            }
            return base.GetDesignerPropertyVisible(propertyName);
        }

        public override string ToString()
        {
            return Resources.Swipe_DisplayName;
        }
    }

    public class ImageItem
    {
        [SRDisplayName(nameof(Resources.Swipe_SwipeItem_Value))]
        [Required]
        public string value { get; set; }

        [SRDisplayName(nameof(Resources.Swipe_SwipeItem_Image))]
        [Required]
        [ImageValueProperty(SupportSvg = false)]
        public ImageValue image { get; set; }
    }
}
